package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//护理计划控制器
@RestController
@Api(tags = "护理计划相关接口")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanService nursingPlanService;

    //条件分页查询
    @GetMapping("/nursing/plan/search")
    @ApiOperation(value = "条件分页查询护理计划", notes = "传入分页条件")
    public ResponseResult<PageResponse<NursingPlanVo>> findByPage(
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status) {
        PageResponse<NursingPlanVo> page = nursingPlanService.findByPage(pageNum, pageSize, name, status);
        return success(page);
    }

    //根据id查询
    @GetMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id进行查询", notes = "传入查询id")
    public ResponseResult<NursingPlanVo> findById(@PathVariable(name = "id") Long id) {
        NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);
        return success(nursingPlanVo);
    }

    // 根据id修改
    @PutMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id进行修改", notes = "传入修改信息")
    public ResponseResult updateById(@RequestBody NursingPlanDto dto) {
        nursingPlanService.updateById(dto);
        return success();
    }

    //新增计划
    @PostMapping("/nursing/plan")
    @ApiOperation(value = "新增护理计划", notes = "传入新增信息")
    public ResponseResult save(@RequestBody NursingPlanDto dto) {
        nursingPlanService.save(dto);
        return success();
    }

    //删除计划
    @DeleteMapping("/nursing/plan/{id}")
    @ApiOperation(value = "根据id进行删除", notes = "传入删除id")
    public ResponseResult deleteById(@PathVariable("id") Long id) {
        nursingPlanService.deleteById(id);
        return success();
    }

    //启用禁用
    @PutMapping("nursing/{id}/status/{status}")
    @ApiOperation(value = "根据id进行启用禁用", notes = "传入修改状态信息")
    public ResponseResult updateStatus(@PathVariable(name="id")Long id,@PathVariable(name="status") Integer status){
        nursingPlanService.updateStatus(id,status);
        return success();
    }
}